﻿
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
using Gift.Model;

namespace WebApp.admin.basic
{
    public partial class logisticsCompany : BaseAdmin
    {
        // Fields
        tbLogisticsCompany oLogisticsCompany = new tbLogisticsCompany();


        // Methods
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            try
            {
                this.oLogisticsCompany.logisticsCompanyName = this.txtLogisticsCompanyName.Value;
                this.oLogisticsCompany.logisticsCompanyUrl = this.txtLogisticsCompanyUrl.Value;
                this.oLogisticsCompany.sortOrder = Convert.ToInt32(this.txtSortOrder.Value);;
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {
                    this.oLogisticsCompany.id = Convert.ToInt32(base.Request.QueryString["id"]);
                    if (BaseFactory.theLogisticsCompany.Update(this.oLogisticsCompany))
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"logisticsCompanyList.aspx\";</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                    }
                }
                else
                {
                    this.oLogisticsCompany.CompanyId = int.Parse(base.Administrator.CompanyId);
                    if (BaseFactory.theLogisticsCompany.Add(this.oLogisticsCompany) > 0)
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");location.href=\"logisticsCompanyList.aspx\";</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                    }
                }
            }
            catch
            {
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }
        }

        public StringBuilder GetTitle()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if (base.Request.QueryString["ot"] == null)
                {
                    return builder;
                }
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {
                    builder.Append("编辑公司");
                    return builder;
                }
                builder.Append("添加公司");
            }
            catch
            {
            }
            return builder;
        }

        private void LogisticsCompanyBind()
        {
            try
            {
                tbLogisticsCompany logisticsCompanyById = BaseFactory.theLogisticsCompany.GetModel(Convert.ToInt32(base.Request.QueryString["id"]));
                if (logisticsCompanyById != null)
                {
                    this.txtLogisticsCompanyName.Value = logisticsCompanyById.logisticsCompanyName;
                    this.txtLogisticsCompanyUrl.Value = logisticsCompanyById.logisticsCompanyUrl;
                    this.txtSortOrder.Value = logisticsCompanyById.sortOrder.ToString();
                }
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
            //{
            //    base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
            //}
            if ((!base.IsPostBack && (base.Request.QueryString["ot"] != null)) && ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null)))
            {
                this.LogisticsCompanyBind();
            }
        }

    }
}